package build_resource

import (
	"go_server/game_server/dao/count_down_dao"
	"go_server/game_server/protocol/pb"
	"go_server/game_server/util"
	"go_server/zinx/ziface"
	"go_server/zinx/zlog"
	"go_server/zinx/znet"
)

type BuildResourceStatesApi struct {
	znet.BaseRouter
}

// 获取资源建筑状态信息
func (*BuildResourceStatesApi) Handle(request ziface.IRequest) {
	msg := &pb.BuildResourceStatesC2S{}
	if !util.PBParseRet(request, msg) {
		return
	}

	conn := request.GetConnection()
	roleId := ServiceObj.GetRoleId(request)

	row := count_down_dao.GetCountDownByRoleId(roleId, []string{"build_states"})

	buildStates := make(map[int32]int64)

	if row != nil && row.BuildStates.Data() != nil {
		buildStates = row.BuildStates.Data()
	}

	res := &pb.BuildResourceStatesS2C{
		BuildStates: buildStates,
	}

	zlog.Infof("res=%v", res)

	// 优先返回下行
	conn.SendBuffPBMsg(uint32(pb.ProtocolManager_BuildResourceStates), res)
}
